<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><li class="fa fa-remove"></li></button>
    <h5 class="modal-title"></h5>
</div>

<div class="modal-body">
    <form id="module_form" name="module_form" class="form-horizontal">
        <input type="hidden" name="id" id="id">
        <input type="hidden" name="version">
        <input type="hidden" name="createDateTime" data-flag="date" data-format="yyyy-mm-dd hh:ii:ss">
        <input type="hidden" name="deleted" value="0">
        <input type='hidden' value="${CSRFToken}" id='csrftoken'>
        <div class="box-body">
            <div class="col-md-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">业务名称<span style="color:red">*</span></label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="name" name="name" placeholder="请填写业务名称">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">业务编码<span style="color:red">*</span></label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="code" name="code" placeholder="请填写业务编码">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">是否可用</label>
                    <div class="col-sm-8">
                        <label class="control-label"> <input type="radio" name="deleted" data-flag="icheck"
                                                             class="square-blue" checked="checked"
                                                             value="0"> 启用
                        </label> &nbsp;&nbsp;&nbsp;
                        <label class="control-label"> <input type="radio" name="deleted" data-flag="icheck"
                                                             class="square-blue" value="1"> 禁用
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">备注</label>
                    <div class="col-sm-8">
                        <textarea class="form-control" id="remark" name="remark" rows="3" placeholder="请填写备注"></textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-footer text-right">
            <button type="button" class="btn btn-default" data-btn-type="cancel" data-dismiss="modal">取消</button>
            <button type="submit" class="btn btn-primary" data-btn-type="save">提交</button>
        </div>
    </form>
</div>
<script>
    var form;
    var id="${id?default(0)}";
    $(function(){
        //初始化表单
        form=$("#module_form").form();
        //数据校验
        $("#module_form").bootstrapValidator({
            message : '请输入有效值',
            feedbackIcons : {
                valid : 'glyphicon glyphicon-ok',
                invalid : 'glyphicon glyphicon-remove',
                validating : 'glyphicon glyphicon-refresh'
            },
            submitHandler : function() {
                modals.confirm('确认保存？', function() {
                    var module = form.getFormSimpleData();
                    ajaxPost(basePath+'/activiti/module/save',module, function(data) {
                        if(data.success){
                            if(id!="0"){
                                modals.hideWin(winId);
                                moduleTable.reloadRowData(id);
                            }else{
                                modals.hideWin(winId);
                                moduleTable.reloadData();
                            }
                        }
                    });
                });
            },
            fields : {
                "name":{
                    validators:{
                        notEmpty:{message:'业务名称不能为空'}
                    }
                },
                "code":{
                    validators:{
                        notEmpty:{message:'业务编码不能为空'},
                        remote:{
                            url:basePath+"/base/checkUnique",
                            data: function(validator) {
                                return {
                                    className:'com.cnpc.framework.activiti.entity.Module',
                                    fieldName:'code',
                                    fieldValue:$('#code').val(),
                                    id:$('#id').val()
                                };
                            },
                            message:'该编码已被使用'
                        }
                    }
                },
            }
        });
        //初始化控件
        form.initComponent();
        //编辑回填
        if(id!=0){
            ajaxPost(basePath+"/activiti/module/get/"+id,null,function(data){
                form.initFormData(data);
            })
        }
    });

</script>
